<?php
/*
 * @version		2.2.0
 * @category	Plugin
 * @package		Joomla
 * @author		Original Author <serafinobilotta@hotmail.com>
 * @license		GNU/GPL, see http://www.gnu.org/licenses/gpl-2.0.html
 * @link		http://www.p2warticles.com/2011/06/scrolling-share-bar-joomla/
 * @since		2.0.0
 */

defined('JPATH_PLATFORM') or die;


class JFormFieldArticlelist extends JFormField
{
	
	protected $type = 'Articlelist';

	
	protected function getInput()
	{
		// Initialize variables.
		$db = &JFactory::getDBO();
		$html = array();
		$attr = '';

		// Initialize some field attributes.
		$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';

		// To avoid user's confusion, readonly="true" should imply disabled="true".
		if ((string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true')
		{
			$attr .= ' disabled="disabled"';
		}

		$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
		$attr .= $this->multiple ? ' multiple="multiple"' : '';

		// Initialize JavaScript field attributes.
		$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';

		$db = &JFactory::getDBO();

		
		$query =    'SELECT a.id, a.title' .
                            ' FROM #__content AS a' .
                            ' WHERE a.state =1' .
                            ' ORDER BY a.id DESC';
		
		$db->setQuery($query);
		$options = $db->loadObjectList();
		
		return JHTML::_('select.genericlist',  $options, $this->name, $attr, 'id', 'title', $this->value, $this->id );
	}
}